package com.smartreader.common;

import lombok.Data;

@Data
public class R<T> {

    /**
     * 状态码
     */
    private Integer code;

    /**
     * 消息
     */
    private String message;

    /**
     * 返回值
     */
    private T data;

    /**
     *
     * @param code
     * @param message
     * @return
     */
    public static R success(Integer code, String message) {
        R result = new R();
        result.code = code;
        result.message = message;
        return result;
    }

    public static <T> R<T> success(Integer code, String message, T data) {
        R<T> result = new R<>();
        result.code = code;
        result.message = message;
        result.data = data;
        return result;
    }

    public static R fail(Integer code, String message) {
        R result = new R();
        result.code = code;
        result.message = message;
        return result;
    }

    public static <T> R<T> fail(Integer code, String message, T data) {
        R<T> result = new R<>();
        result.code = code;
        result.message = message;
        result.data = data;
        return result;
    }
}